package ua.khuta.myskidka;

import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SimpleCursorAdapter;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;

public class FragmentSubcategoryList extends Fragment {
	View v;
	Database db;
	ListView lvSubcategories;
	SimpleCursorAdapter scAdapter;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		v = inflater.inflate(R.layout.fragment_subcategories, null);
		lvSubcategories = (ListView) v.findViewById(R.id.lv_subcategories);
		db = Database.getInstance(getActivity());
		Bundle bund = getArguments();
		int categoryId=bund.getInt("categoryId");
		Log.d("myLogs", "subcategoryCategoryId"+categoryId);
		Cursor c = db.getSubcategoriesByCategoryId(categoryId);
		String[] from = { Database.SUBCATEGORY_TITLE,
				Database.SUBCATEGORY_OBJECTS_COUNT };
		int[] to = { R.id.tv_subcategory_title,
				R.id.tv_subcategory_object_count };
		scAdapter = new SimpleCursorAdapter(getActivity(),
				R.layout.item_subcategory, c, from, to);
		lvSubcategories.setAdapter(scAdapter);
		return v;
	}
}
